package cn.lumora.service;

import cn.hutool.core.util.ObjectUtil;
import cn.lumora.pojo.Player;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.IService;
import lombok.extern.slf4j.Slf4j;

/**
 * 玩家服务
 */
public interface PlayerService extends IService<Player> {

    /**
     * 检查用户名是否存在
     * @param username 用户名
     * @return 存在返回true
     */
    default boolean checkUsername(String username) {
        LambdaQueryWrapper<Player> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.select(Player::getUsername);
        queryWrapper.eq(Player::getUsername, username);
        queryWrapper.last("limit 1");
        return ObjectUtil.isNotEmpty(this.list(queryWrapper));
    }

    /**
     * 根据用户名查询玩家信息
     * @param username 用户名
     * @return 玩家信息
     */
    Player getPlayerByUsername(String username);
}
